{% extends "base_generic.html" %}
{% load static %}
{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/user_management.css' %}">
{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h1 class="mb-0"><i class="fas fa-language"></i> 语言: {{ language.name }}</h1>
        </div>
        <div class="card-body">
            {% if perms.catalog.change_language or perms.catalog.delete_language %}
            <div class="mb-4">
                {% if perms.catalog.change_language %}
                    <a href="{% url 'language-update' language.id %}" class="btn btn-primary"><i class="fas fa-edit"></i> 更新语言</a>
                {% endif %}
                {% if not language.book_set.all and perms.catalog.delete_language %}
                    <a href="{% url 'language-delete' language.id %}" class="btn btn-danger ms-2"><i class="fas fa-trash"></i> 删除语言</a>
                {% endif %}
            </div>
            {% endif %}
            
            <h4><i class="fas fa-book"></i> 书籍列表</h4>
            
            {% if language.book_set.all %}
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>书名</th>
                        <th>作者</th>
                        <th>类型</th>
                    </tr>
                </thead>
                <tbody>
                    {% for copy in language.book_set.all %}
                    <tr>
                        <td><a href="{{ copy.get_absolute_url }}">{{ copy.title }}</a></td>
                        <td>{{ copy.author }}</td>
                        <td>{{ copy.genre.all|join:", " }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
                <div class="alert alert-info">该语言暂无书籍。</div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}

{% block sidebar %}
  {{ block.super }}
{% endblock %}